package com.just.fun.thread;

public class InterruptThread {

    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {

                    while (!Thread.currentThread().isInterrupted()){
                        try {
                            Thread.sleep(500);
                            doTask();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                            //Thread.currentThread().interrupt();
                        }

                    }
            }
        });

        t1.start();
        Thread.sleep(1000);
        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
               t1.interrupt();
            }
        });
        t2.start();
    }

    public static void doTask(){
        System.out.println("工作中。。。");
    }
}
